<?php

namespace app\index\validate;

use think\Validate;

class Topic extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */
	protected $rule = [
        'id' => 'require|gt:0|token',
        'title' => 'require|length:3,50|token',
        'body' => 'require|min:3',
        'category_id' => 'require|egt:1',
        'sort_num' => 'between:0,99999',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */
    protected $message = [
        'id.require' => 'ID不能为空',
        'id.gt' => 'ID错误',
        'id.token' => '表单令牌不正确',
        'title.require' => '标题不能为空',
        'title.length' => '标题长度必须在3-50个字符之间',
        'title.token' => '表单令牌不正确',
        'body.require' => '正文不能为空',
        'body.min' => '正文至少包含3个字符',
        'category_id.require' => '分类不能为空',
        'category_id.gt' => '分类不能为空',
        'sort_num.between' => '排序编号必须在0~99999之间',
    ];

    protected $scene = [
        'create_or_update'  =>  ['title','body', 'category_id', 'sort_num'],
        'delete'  =>  ['id'],
    ];
}
